package com.aier.entrance.service.impl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.aier.entrance.common.EntranceServerData;
import com.aier.entrance.entity.EntranceDevice;
import com.aier.entrance.service.IEntranceCardService;
import com.aier.entrance.service.IEntranceInitCommonService;
import com.aier.entrance.service.IVideoDeviceService;

@Component("entranceInitCommonService")
public class EntranceInitCommonService implements IEntranceInitCommonService{

    @Resource(name="entranceCardService")
    private IEntranceCardService entranceCardService;
    @Resource(name="videoDeviceService")
    private IVideoDeviceService videoDeviceService;
    
    @Override
    public void initEntrance(){
        initED();
    }
    
    private void initED(){
        System.out.println("初始化门禁设备"+new Timestamp(new java.util.Date().getTime()));
        if(null==EntranceServerData.mapED){
            EntranceServerData.mapED=new HashMap<String,EntranceDevice>();
        }
        List<EntranceDevice> li=entranceCardService.searchEntranceDeviceAll();
        EntranceServerData.mapED.clear();
        for(int i=0;i<li.size();i++){
            EntranceDevice ed=li.get(i);
            ed.setVd(videoDeviceService.searchVideoDevice(ed.getVdid()));
            EntranceServerData.mapED.put(ed.getSn(), ed);
        }
    }

    public void setEntranceCardService(IEntranceCardService entranceCardService) {
        this.entranceCardService = entranceCardService;
    }

    public void setVideoDeviceService(IVideoDeviceService videoDeviceService) {
        this.videoDeviceService = videoDeviceService;
    }
}
